<template>
  <div class="login-container">
    <div id="window" ref="window" class="window">
      <div class="page page-front">
        <div class="page-content">
          <div class="input-row">
            <label class="label fadeIn">Account</label>
            <input
              v-model="user.userId"
              class="input fadeIn delay1"
              type="text"
              placeholder="请输入账号"
            />
          </div>
          <div class="input-row">
            <label class="label fadeIn delay2">Password</label>
            <input
              v-model="user.userPassword"
              class="input fadeIn delay3"
              type="password"
              placeholder="请输入密码"
            />
          </div>
          <div class="input-row">
            <label class="label fadeIn delay4">type</label>
            <input
              v-model="user.type"
              class="input fadeIn delay5"
              type="text"
              placeholder="请输入身份"
            />
          </div>
          <div class="input-row perspective">
            <button
              @click="Login"
              :class="['button', 'load-btn', 'fadeIn', 'delay6', ]"
              type="button"
            >
              <span class="default">
                <i class="ion-arrow-right-b"></i>
                Login
              </span>
              <span class="load-state">
                <span class="ball"></span>
                <span class="ball"></span>
                <span class="ball"></span>
              </span>
            </button>
          </div>
        </div>
      </div>
      <div class="page page-back">
        <div class="page-content">
          <img
            class="avatar"
            src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/22043/avatar.jpg"
            alt="Avatar"
          />
          <p class="welcome">Welcome back, Dog!</p>
          <div class="perspective">
            <button
              class="button inline trigger-anim-replay"
              type="button"
            >
              <i class="ion-refresh"></i>
              Replay animation
            </button>
          </div>
        </div>
      </div>
    </div>
    <div
      v-show="showBrowserWarning"
      class="browser-warning"
    >
      Glitchy or weird animation? Let it play through once, then press Replay.
    </div>
  </div>
</template>

<script>
import axios from 'axios'
import Center from '../center/Center.vue';

export default {
  name: "Login",
  components: {
    Center
  },
  data() {
    return {
      user:{
          userId: "",
          userPassword: "",
          type: ""
      },
      showBrowserWarning: false
    };
  },
  mounted() {
    
    
  },
  methods: {
Login() {
  axios.post('http://localhost:9999/user/getUserByIandP', this.user)
    .then(res => {
      console.log(res.data);
      localStorage.setItem('users', JSON.stringify(res.data));
      // 更新当前组件的状态，而不是直接覆盖 user 对象
      Object.assign(this.user, res.data); // 使用 Object.assign 或者展开运算符来合并对象
      
      if (res.data) { // 检查响应数据是否存在且不是空对象
        this.$message({
          message: '登录成功',
          type: 'success'
        });
        // 这里可以导航到其他页面或进行其他操作
        this.$router.push({ path: '/layout/home' });
      } else {
        this.$message({
          message: '登录失败，请检查账号密码',
          type: 'error'
        });
      }
    })
    .catch(error => {
      console.error(error);
      this.$message({
        message: '登录失败，请检查网络连接或服务器状态',
        type: 'error'
      });
    });
},
}
};
</script>

<style scoped>
.login-container {
  position: relative;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background-image: url('./beijin.png'); /* 替换为你实际的背景图片链接 */
  background-size: cover;
  background-position: center;
}
/* 保留大部分原有的样式代码，以下是部分示例，实际应用中需完整复制原样式中对应规则 */
.window {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  height: 450px;
  width: 450px;
  color: #fff;
  animation: 1.5s window ease-in-out backwards;
  transform-style: preserve-3d;
  transition-property: height width;
  z-index: 1; /* 提高窗口的层级，确保在背景之上显示 */
}
.page {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  transform: translateZ(0);
  background: rgba(68, 68, 68, 0.8); /* 给页面添加半透明背景，使其内容更清晰显示在背景图之上 */
  background-image: linear-gradient(bottom, #444, #333);
  border-radius: 6px;
  padding: 60px;
}

.page-back {
  text-align: center;
  transform: rotateX(180deg);
}
.page-back.page-content {
  opacity: 0;
}
.page-back.avatar {
  height: 150px;
  width: 150px;
  border: 5px solid #fff;
  margin: 30px auto 40px auto;
  display: block;
  opacity: 0;
  transform: scale(0.1);
  border-radius: 1000px;
}
.page-back.welcome {
  font-size: 22px;
  margin-bottom: 40px;
}
.page-back.welcome,
.page-back.perspective {
  opacity: 0;
  transform: translateY(-30px);
}
.input-row {
  margin: 0 0 30px;
}
.input-row:last-of-type {
  margin-bottom: 0;
}
.perspective {
  perspective: 1000px;
}
.label {
  font-family: sans-serif;
  text-transform: uppercase;
  font-size: 12px;
  margin: 0 0 10px 0;
  color: #fff;
  display: block;
  cursor: pointer;
}
.input {
  padding: 0 15px;
  height: 40px;
  line-height: 40px;
  outline: none;
  border: 0;
  background: #fff;
  display: block;
  width: 100%;
  border-radius: 3px;
  transition-duration: 0.2s;
}
.input:focus,
.input.fyll-focus {
  box-shadow: 0 0 0 3px #D85C89;
}
.button {
  height: 50px;
  line-height: 50px;
  padding: 0 20px;
  margin: 0;
  text-align: center;
  color: #fff;
  border: 0;
  display: block;
  width: 100%;
  outline: none;
  cursor: pointer;
  overflow: hidden;
  font-size: 17px;
  background: #D85C89;
  border-radius: 3px;
  background-image: linear-gradient(bottom, #D85C89, #E7779F);
  box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.4), 0 0 4px rgba(0, 0, 0, 0.5);
  transition-duration: 0.1s;
  transform-style: preserve-3d;
  transform-origin: bottom;
  transform: translateZ(0);
  backface-visibility: hidden;
  z-index: 2; /* 提高按钮的层级，确保在页面之上显示 */
}
.button i {
  margin-right: 10px;
}
.button:active,
.button.fyll-focus {
  background: #D85C89;
  background-image: linear-gradient(bottom, #D85C89, #D85C89);
  transform: rotateX(20deg);
}
.button.inline {
  width: auto;
  display: inline-block;
}
.button.load-btn {
.default,
.load-state {
    transition-duration: 0.2s;
  }
.load-state {
    position: absolute;
    top: -50px;
    left: 0;
    right: 0;
    height: 100%;
    text-align: center;
    line-height: 50px;
    pointer-events: none;
  }
.load-state.ball {
    height: 10px;
    width: 10px;
    margin-right: 10px;
    background: #fff;
    display: inline-block;
    border-radius: 1000px;
    animation: ballBounce 0.3s alternate infinite;
    animation-timing-function: cubic-bezier(0.2, 0.4, 0.3, 1);
    transition-duration: 0.3s;
  }
.load-state.ball:nth-child(2n) {
    animation-delay: 0.05s;
  }
.load-state.ball:nth-child(3n) {
    animation-delay: 0.1s;
  }
.load-state.ball:last-child {
    margin-right: 0;
  }
  &.done {
 .ball {
      opacity: 0;
    }
  }
  &.loading {
 .default {
      transform: translateY(50px);
      opacity: 0;
    }
 .load-state {
      transform: translateY(50px);
    }
  }
}
.browser-warning {
  background: rgba(0, 0, 0, 0.7);
  padding: 15px 0;
  color: #fff;
  position: absolute;
  top: 50px;
  left: 0;
  right: 0;
  margin: auto;
  width: 530px;
  text-align: center;
  border-radius: 3px;
  transition-duration: 0.5s;
  transition-timing-function: cubic-bezier(0.015, 0.695, 0.340, 1.365);
}
.browser-warning.hidden {
  opacity: 0;
  transform: scale(0.2);
}
.fadeIn {
  animation: 1s fadeIn cubic-bezier(0.015, 0.695, 0.340, 1.365) backwards;
}
.delay1 {
  animation-delay: 1.6s;
}
.delay2 {
  animation-delay: 1.7s;
}
.delay3 {
  animation-delay: 1.8s;
}
.delay4 {
  animation-delay: 1.9s;
}
.delay5 {
  animation-delay: 2.0s;
}
.delay6 {
  animation-delay: 2.1s;
}
@keyframes window {
  0% {
    transform: scale(0) rotateX(360deg);
    height: 150px;
    width: 150px;
  }
  50% {
    transform: none;
    height: 150px;
  }
  75% {
    height: 350px;
    width: 150px;
  }
  100% {
    width: 450px;
  }
}
@keyframes fadeIn {
  0% {
    opacity: 0;
    transform: translateY(30px);
  }
  100% {
    opacity: 1;
    transform: none;
  }
}
@keyframes ballBounce {
  0% {
    transform: translateY(25%);
  }
  100% {
    transform: translateY(-75%);
  }
}
</style>